package Hbase;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

public class UpdateDemo {
    public static void main(String[] args) throws Exception{
        Configuration config = HBaseConfiguration.create();
        config.addResource(new Path(ClassLoader.getSystemResource("hbase-site.xml").toURI()));
        config.addResource(new Path(ClassLoader.getSystemResource("core-site.xml").toURI()));
        //config.set("hbase.master", "node1:16010");


        try(Connection connection = ConnectionFactory.createConnection(config);){
            Table table = connection.getTable(TableName.valueOf("mytable")) ;
            Put put = new Put(Bytes.toBytes("row1")) ;
            //put.addColumn( Bytes.toBytes("mycf"),Bytes.toBytes("name"),Bytes.toBytes("lisi")) ;
            put.addColumn(Bytes.toBytes("mycf"),Bytes.toBytes("age"),Bytes.toBytes( new Integer(27).toString() )) ;
            table.put(put) ;

            Get get = new Get(Bytes.toBytes("row1")) ;
            Result result = table.get(get) ;
            byte[] value = result.getValue(Bytes.toBytes("mycf") , Bytes.toBytes("age")) ;
            System.out.println(Integer.valueOf(Bytes.toString(value)));
        }
    }
}
